Examples > Creating a Database Snapshot |
The snapshot functionality you allows to save the schema of the database to a file. Once created, the snapshot is disconnected from the database and provides an offline, read-only view of the database schema.
The snapshot provided by the SDK uses a proprietary format to store the database schema. It is not compatible with the SQL Server database snapshot.
The following example demonstrates how to create a database snapshot.
using xSQL.Schema.Core; using xSQL.Schema.SqlServer; using xSQL.SchemaCompare.SqlServer; namespace xSQL.Sdk.SchemaCompare.Examples { class DatabaseSnapshot { /// <summary> /// Creates a snapshot for the AdventureWorks database /// </summary> public static void CreateSnapshot() { SqlServer server; SqlDatabase database; try { //--create the SQL Server object, connect using Windows authentication server = new SqlServer(@"(local)"); //--create the database object database = server.GetDatabase("AdventureWorks"); //--attach an event handler to SchemaOperation event in order to get progress information during the schema read database.SchemaOperation += new EventHandler<SchemaOperationEventArgs>(database_SchemaOperation); //--attach an handler to SnapshotOperation event to get snapshot feedback database.SnapshotOperation += new EventHandler<SnapshotOperationEventArgs>(database_SnapshotOperation); //--read the database schema database.ReadSchema(); //--create the snapshot database.SaveToSnapshot(Path.Combine(@"C:\", database.GetDefaultSnapshotFilename())); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } private static void database_SchemaOperation(object sender, SchemaOperationEventArgs e) { //--exclude verbose messages if (e.Message.MessageType != OperationMessageTypeEnum.Verbose) Console.WriteLine(e.Message.Text); } private static void database_SnapshotOperation(object sender, SnapshotOperationEventArgs e) { //--exclude verbose messages if (e.Message.MessageType != OperationMessageTypeEnum.Verbose) Console.WriteLine(e.Message.Text); } } }